//
//  HeadMessageView.swift
//  ZBWb
//
//  Created by 天隐翎 on 16/4/6.
//  Copyright © 2016年 csdn. All rights reserved.
//

import UIKit

class HeadMessageView: UIView {
    
    @IBOutlet weak var textField: UITextField!
    
    @IBOutlet weak var righttrailing: NSLayoutConstraint!
    
    @IBOutlet weak var buttonqu: UIButton!
    
    @IBAction func didtextfield(sender: AnyObject) {
        
        //        改变输入框的大小,修改约束
        righttrailing.constant = buttonqu.frame.width
        //        刷新页面
        UIView.animateWithDuration(0.25) { () -> Void in
            self.layoutIfNeeded()
        }
        
        
    }
    @IBAction func didbuttonquxiao(sender: AnyObject) {
//        取消键盘第一相应者
        textField.resignFirstResponder()

        //        改变输入框的大小,修改约束
        righttrailing.constant = 0
        //        刷新页面
        UIView.animateWithDuration(0.25) { () -> Void in
            self.layoutIfNeeded()
        }
        
        
    }
    override func awakeFromNib() {
//        设置frame
        self.frame = CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, self.bounds.height)
        
//        设置放大镜
        self.textField.leftView = UIImageView(image: UIImage(named: "searchbar_textfield_search_icon"))
        self.textField.leftView?.frame = CGRectMake( 0, 0, self.bounds.height, self.bounds.height)
        self.textField.leftView?.contentMode = .Center
        self.textField.leftViewMode = .Always
        
        
//        设置圆角
        textField.layer.cornerRadius = 8
        textField.layer.masksToBounds = true
        
        
    }

//    定义一个类方法来获取xib
    class func loadsearchmessage() -> HeadMessageView {
        let v = NSBundle.mainBundle().loadNibNamed("HeadMessage", owner: nil, options: nil).last as! HeadMessageView
        return v
    }
    

}
